﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;

namespace ElkiTools.SPListCaller.Core.Exceptions
{
    public class WSCallException : ApplicationException
    {
        public string ErrorMessage { get; set; }

        public WSCallException(string message, Exception InnerException)
            : base(message, InnerException)
        {
            if (InnerException is SoapException)
            {
                ErrorMessage = ((SoapException)InnerException).Detail.InnerText;
            }
            else
            {
                ErrorMessage = InnerException.Message;
            }
        }

        public override string Message
        {
            get
            {
                if(string.IsNullOrEmpty(base.Message))
                {
                    return ErrorMessage;
                }
                else
                {
                    return base.Message + Environment.NewLine + ErrorMessage;
                }
            }
        }
    }
}
